package com.neusoft.elmboot.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.service.BusinessService;

@RestController
@RequestMapping("/Businesses")
public class BusinessController {
	
	@Autowired
	private BusinessService businessService;

	@GetMapping("/orderTypeId/{orderTypeId}")
	public List<Business>  listBusinessByOrderTypeId(Business business) throws Exception{
		return businessService.listBusinessByOrderTypeId(business.getOrderTypeId());
	}
	
	@GetMapping("/businessId/{businessId}")
	public Business getBusinessById(Business business) throws Exception{
		return businessService.getBusinessById(business.getBusinessId());
	}
	
	@GetMapping("/words/{words}")
	public List<Business> listBusinessByWords(@PathVariable String words) throws Exception{
		return businessService.listBusinessByWords(words);
	}
	
	@PostMapping("/name/{businessName}/address/{businessAddress}/explain/{businessExplain}/img/{businessImg}/orderTypeId/{orderTypeId}/starPrice/{starPrice}/deliveryPrice/{deliveryPrice}/remarks/{remarks}/userId/{userId}")
	public int createBusiness(Business business) throws Exception{
		String img1 = business.getBusinessImg().replace("-", "/").replace("_", "+").replace("~", ";");
		business.setBusinessImg(img1);
		return businessService.createBusiness(business);
	}
	
	@PutMapping("businessId/{businessId}/name/{businessName}/address/{businessAddress}/explain/{businessExplain}/img/{businessImg}/orderTypeId/{orderTypeId}/starPrice/{starPrice}/deliveryPrice/{deliveryPrice}/remarks/{remarks}")
	public int updateBusiness(Business business) throws Exception{
		String img1 = business.getBusinessImg().replace("-", "/").replace("_", "+").replace("~", ";");
		business.setBusinessImg(img1);
		return businessService.updateBusiness(business);
	}
	
	@GetMapping("userId/{userId}")
	public Business getBusinessByUserId(Business business) {
		return businessService.getBusinessByUserId(business.getUserId());
	}
}
 